﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Chizx.Web.companys
{
    public partial class Add : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (null == Session["UserEntity"])
            {
                Response.Redirect("/e/Login.aspx");
            }       
        }

        		protected void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtzcom_name.Text.Trim().Length==0)
			{
				strErr+="zcom_name不能为空！\\n";	
			}
			if(this.txtzcom_address.Text.Trim().Length==0)
			{
				strErr+="zcom_address不能为空！\\n";	
			}
			if(this.txtzcom_desc.Text.Trim().Length==0)
			{
				strErr+="zcom_desc不能为空！\\n";	
			}
		
			if(!PageValidate.IsNumber(txtzcom_neednum.Text))
			{
				strErr+="zcom_neednum格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			string zcom_name=this.txtzcom_name.Text;
			string zcom_address=this.txtzcom_address.Text;
			string zcom_desc=this.txtzcom_desc.Text;
			int zcom_applynum=0;
			int zcom_passnum=0;
			int zcom_neednum=int.Parse(this.txtzcom_neednum.Text);

			Chizx.Model.CompanysModel model=new Chizx.Model.CompanysModel();
			model.zcom_name=zcom_name;
			model.zcom_address=zcom_address;
			model.zcom_desc=zcom_desc;
			model.zcom_applynum=zcom_applynum;
			model.zcom_passnum=zcom_passnum;
			model.zcom_neednum=zcom_neednum;
            model.zcom_createdate = Chizx.Common.DateHelper.getUtcNow();
			model.zcom_status="c0";

            //写入系统日志
            if (Session["UserEntity"] == null)
            {
                Response.Redirect("/e/Login.aspx");
            }
            else
            {
                Chizx.BLL.CompanysBll bll = new Chizx.BLL.CompanysBll();
                bll.Add(model);
                Chizx.Model.UserModel sbmmodel = (Chizx.Model.UserModel)Session["UserEntity"];
                Chizx.BLL.SystemLogBll sbll = new Chizx.BLL.SystemLogBll();
                Chizx.Model.SystemLogModel slm = new Chizx.Model.SystemLogModel();
                slm.zu_id = sbmmodel.zu_id;
                slm.zl_dowhen = DateTime.Now;
                slm.zl_dowhat = "添加招聘单位";
                slm.zl_dotype = "3";//0:Test,1:Auth,2:Read,3:Write,4:Del,5:Inpor
                slm.zl_dodesc = "操作成功";
                sbll.Add(slm);
                Chizx.Model.MessageModel mm = new Chizx.Model.MessageModel();
                Chizx.BLL.MessageBll mb = new Chizx.BLL.MessageBll();
                mm.zu_id = sbmmodel.zu_id;
                mm.zmsg_topic = "实习单位成功添加";
                mm.zmsg_context = "尊敬的管理员 " + sbmmodel.zu_id + " ,你新添加的招聘单位信息已经成功录入系统！";
                mm.zmsg_createdate = DateTime.Now;
                mm.zmsg_status = "m0";
                mb.Add(mm);
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");
            }
		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
